private["_busdriver","_lastBusStop","_sleepTime","_list"];
_sleepTime=0.5;
_lastBusStop=objNull;
_busdriver=_this select 0;
(vehicle _busdriver) setVariable ["atBusStop", false];
while {true} do {
	
	_list = nearestObjects [vehicle _busdriver,[],10];
	
	_sleepTime=0.5;
	
	//if({ [_x,"bus"] call KRON_StrInStr } count _list > 0)then{
		{
			scopeName "loop";			
			
			if ((_lastBusStop != _x) and ([str _x,"busstop"] call KRON_StrInStr) ) then
			{
				//hint ("BUSSTOP !!"+str time+" : "+str _x);
				
				_busdriver setSpeedMode "LIMITED";//limitSpeed 25;
				
				_sleepTime=0.2;
				
				if( ((_busdriver) distance _x < 10) and (_lastBusStop != _x) ) then {
					
					_lastBusStop = _x;
					
					_busdriver disableAI "MOVE";
					//hint ("wait for person to get in the bus ");
					(vehicle _busdriver) setVariable ["atBusStop", true];
					sleep 5;
					//hint ("lets continue ");
					_busdriver enableAI "MOVE";
					
					//_busdriver limitSpeed 200;
					_busdriver setSpeedMode "FULL";
					(vehicle _busdriver) setVariable ["atBusStop", false];
					
					breakout "loop";
				};
				
				
			};
			
			//Player globalChat "test";

		}forEach _list;
		
	
	
	sleep _sleepTime;
	_busdriver setSpeedMode "FULL";
}; 

//_list = nearestObjects [player,[],10];
/* _str="";
{

	_str = _str+"\n"+ str typeOf _x+" : "+  str _x;
	
}foreach _list;

hint _str; */

// Player globalChat str (getPos player nearestObject 1044213);

// Player globalChat str ((getPos player nearestObject 964677) isKindOf  "Building");